package com.freecloud.javabasics.design.decorator.passport;

import com.freecloud.javabasics.design.adapter.ResultMsg;

/**
 * 扩展新的功能，保证老代码不动
 * @Author: maomao
 * @Date: 2019-11-18 10:44
 */
public class LoginForThirdServiceImpl implements LoginForThirdService {

    private LoginService service;

    public LoginForThirdServiceImpl(LoginService service){
        this.service = service;
    }

    @Override
    public ResultMsg regist(String userName, String password) {
        return service.regist(userName,password);
    }

    @Override
    public ResultMsg login(String userName, String password) {
        return service.login(userName,password);
    }



    @Override
    public ResultMsg loginForQQ(String openId){
        //1、openid是全局唯一，我们可以把他当做是一个用户名

        //2. 密码默认为123
        String password = "123";

        //3. 注册（在原有系统里创建一个用户）

        ResultMsg msg = service.regist(openId,password);
        System.out.println(msg);

        //4. 调用原来的登录方法
        ResultMsg loginMsg = service.login(openId,password);
        System.out.println(loginMsg);


        return loginMsg;
    }
    @Override
    public ResultMsg loginForWechat(String openId){
        return null;
    }
    @Override
    public ResultMsg loginForToken(String token){
        //通过token拿到用户信息，然后重新登录一次
        return null;
    }

    @Override
    public ResultMsg loginForTelphone(String telphoto,String code){
        return null;
    }
    @Override
    public ResultMsg loginForRegist(String username,String password){

        service.regist(username,password);

        return service.login(username,password);
    }


}
